package operation;

import book.Book;
import book.BookList;

public class DelOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("删除图书！");
        System.out.println("请输入你要删除的图书的名字：");
        String name = scanner.nextLine();
        int size = bookList.getUsedSize();
        int i = 0;
        for (i = 0; i < size; i++) {
            Book book = bookList.getPos(i);
            if (name.equals(book.getName())){
                break;
            }
        }
        if (i >= size){
            System.out.println("没有此书，删除失败！");
            return;
        }
        //删
        for (int j = i; j < size - 1; j++) {
            Book book = bookList.getPos(j + 1);
            bookList.setBook(j,book);
        }
        bookList.setBook(size,null);
        bookList.setUsedSize(size - 1);
        System.out.println("删除成功");
    }
}
